package com.paipai.jwtproperty;

import java.io.File;
import java.security.PrivateKey;
import java.security.PublicKey;

import javax.annotation.PostConstruct;


import org.springframework.context.annotation.Configuration;
import org.springframework.context.annotation.PropertySource;
import org.springframework.stereotype.Component;

import com.paipai.utils.RsaUtils;

@Component
public class JwtProperties {
	
	
	private  String secret="paipai@Login(Auth}*^31)&heiMa%"; // 密钥
	
	
	private  String pubKeyPath="D:\\javaplug\\rsa\\rsa.pub";// 公钥地址
	
	
	private  String priKeyPath="D:\\javaplug\\rsa\\rsa.pri";// 私钥地址
	
	
	private  int expire=120;// token过期时间

	private PublicKey publicKey; // 公钥

	private PrivateKey privateKey; // 私钥
	
	
	
	 /**
     * @PostContruct：在构造方法执行之后执行该方法
     */
    @PostConstruct
    public void init(){
        try {
            File pubKey = new File(pubKeyPath);
            File priKey = new File(priKeyPath);
            if (!pubKey.exists() || !priKey.exists()) {
                // 生成公钥和私钥
            	System.out.println("生成公钥和私钥");
                RsaUtils.generateKey(pubKeyPath, priKeyPath, "AA");
            }
            // 获取公钥和私钥
            this.publicKey = RsaUtils.getPublicKey(pubKeyPath);
            this.privateKey = RsaUtils.getPrivateKey(priKeyPath);
        } catch (Exception e) {
            System.out.println("生成钥匙失败");
            throw new RuntimeException();
        }
    }



	public String getSecret() {
		return secret;
	}



	public void setSecret(String secret) {
		this.secret = secret;
	}



	public String getPubKeyPath() {
		return pubKeyPath;
	}



	public void setPubKeyPath(String pubKeyPath) {
		this.pubKeyPath = pubKeyPath;
	}



	public String getPriKeyPath() {
		return priKeyPath;
	}



	public void setPriKeyPath(String priKeyPath) {
		this.priKeyPath = priKeyPath;
	}



	public int getExpire() {
		return expire;
	}



	public void setExpire(int expire) {
		this.expire = expire;
	}



	public PublicKey getPublicKey() {
		return publicKey;
	}



	public void setPublicKey(PublicKey publicKey) {
		this.publicKey = publicKey;
	}



	public PrivateKey getPrivateKey() {
		return privateKey;
	}



	public void setPrivateKey(PrivateKey privateKey) {
		this.privateKey = privateKey;
	}
	
	
	
	

}
